//
//  ViolationInfoCarHeadCell.m
//  carcareIOS
//
//  Created by ileo on 16/8/2.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "ViolationInfoCarHeadView.h"

#define HEIGHT (165 * __MAIN_RATIO_375)

@interface ViolationInfoCarHeadView ()

@property (nonatomic, strong) UIImageView *iconIV;
@property (nonatomic, strong) UILabel *carInfoL;
@property (nonatomic, strong) UILabel *vNumsL;
@property (nonatomic, strong) UILabel *vMoneyL;
@property (nonatomic, strong) UILabel *vPointL;

@end

@implementation ViolationInfoCarHeadView

+(CGFloat)height{
    return HEIGHT;
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.iconIV = [[UIImageView imageViewWithFrame:CGRectMake(53 * __MAIN_RATIO_375, 21 * __MAIN_RATIO_375, 107 * __MAIN_RATIO_375, 52 * __MAIN_RATIO_375) image:ImageNamed(@"BRCarStyleNormalImage")] setupOnView:self];
        self.carInfoL = [[[[UILabel viewWithFrame:CGRectMake(self.iconIV.right + 20 * __MAIN_RATIO_375, self.iconIV.top, 200 * __MAIN_RATIO_375, self.iconIV.height)] labelResetNumberOfLines:0] labelResetTextAlignment:NSTextAlignmentLeft] setupOnView:self];
        self.vNumsL = [[[[UILabel viewWithFrame:CGRectMake(0, 83 * __MAIN_RATIO_375, __MAIN_WIDTH / 3, 82 * __MAIN_RATIO_375)] labelResetTextAlignment:NSTextAlignmentCenter] labelResetNumberOfLines:0] setupOnView:self];
        self.vMoneyL = [[[[UILabel viewWithFrame:CGRectMake(self.vNumsL.right, self.vNumsL.top, self.vNumsL.width, self.vNumsL.height)] labelResetTextAlignment:NSTextAlignmentCenter] labelResetNumberOfLines:0] setupOnView:self];
        self.vPointL = [[[[UILabel viewWithFrame:CGRectMake(self.vMoneyL.right, self.vNumsL.top, self.vNumsL.width, self.vNumsL.height)] labelResetTextAlignment:NSTextAlignmentCenter] labelResetNumberOfLines:0] setupOnView:self];
        
        [[[UIView viewWithFrame:CGRectMake(0, HEIGHT, __MAIN_WIDTH, 0.5)] resetBackgroundColor:[Theme lineColor]] setupOnView:self];
        
    }
    return self;
}

-(void)setVioCarModel:(VioCarModel *)vioCarModel{
    _vioCarModel = vioCarModel;
    
    if ([vioCarModel.carinfoModel.modelImg isNotNil]) {
        [self.iconIV setImageWithURL:[NSURL URLWithString:vioCarModel.carinfoModel.modelImg] placeholderImage:ImageNamed(@"BRCarStyleNormalImage")];
        CGPoint center = self.iconIV.center;
        self.iconIV.height = self.iconIV.width * self.iconIV.image.size.height / self.iconIV.image.size.width;
        [self.iconIV setCenter:center];
    }
    self.carInfoL.attributedText = [self attWithCarNum:vioCarModel.carinfoModel.carno carCitys:[NSString stringWithFormat:@"查询城市:%@",vioCarModel.showCitys]];
    self.vNumsL.attributedText = [self attWithValue:[NSString stringWithFormat:@"%zd",vioCarModel.vioCount] title:@"违章"];
    self.vMoneyL.attributedText = [self attWithValue:[NSString stringWithFormat:@"%.0f",vioCarModel.vioMoney] title:@"罚款"];
    self.vPointL.attributedText = [self attWithValue:[NSString stringWithFormat:@"%zd",vioCarModel.vioPoint] title:@"扣分"];
}

#pragma mark -

-(NSAttributedString *)attWithCarNum:(NSString *)carNum carCitys:(NSString *)carCitys{
    NSAttributedString *att1 = [[[NSAttributedString attributedStringWithText:carNum] copyAttributedStringWithFont:FONT_DEFAULT_Light(16)] copyAttributedStringWithColor:COLOR_HEXSTRING(@"#2e2e2e")];
    NSAttributedString *att2 = [[NSAttributedString attributedStringWithText:@"\n\n"] copyAttributedStringWithFont:FONT_DEFAULT_Light(5)];
    NSAttributedString *att3 = [[[NSAttributedString attributedStringWithText:carCitys] copyAttributedStringWithFont:FONT_DEFAULT_Light(12)] copyAttributedStringWithColor:COLOR_HEXSTRING(@"#a4a4a4")];
    return [NSAttributedString attributedStringWithAttributedStrings:@[att1,att2,att3]];
}

-(NSAttributedString *)attWithValue:(NSString *)value title:(NSString *)title{
    NSAttributedString *att1 = [[[NSAttributedString attributedStringWithText:value] copyAttributedStringWithFont:FONT_DEFAULT_Bold(20)] copyAttributedStringWithColor:COLOR_HEXSTRING(@"#fd6500")];
    NSAttributedString *att2 = [[NSAttributedString attributedStringWithText:@"\n\n"] copyAttributedStringWithFont:FONT_DEFAULT_Light(5)];
    NSAttributedString *att3 = [[[NSAttributedString attributedStringWithText:title] copyAttributedStringWithFont:FONT_DEFAULT_Light(13)] copyAttributedStringWithColor:COLOR_HEXSTRING(@"#424242")];
    return [NSAttributedString attributedStringWithAttributedStrings:@[att1,att2,att3]];
}

@end
